package cn.cheln.explorer.func.setup;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser.Package;
import android.net.Uri;
import android.util.DisplayMetrics;
import cn.cheln.explorer.actions.OperationUtil;
import cn.cheln.explorer.beans.ReportInfo;
import cn.cheln.explorer.config.Constants;
import cn.cheln.explorer.ds.scan.PinyinHelper;
import cn.cheln.support.data.text.xml.SPUtil;
import cn.cheln.support.log.Logs;
import cn.cheln.support.mobile.root.Root;
import cn.cheln.support.secret.SecretUtil;
import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class InstallHelper
{
  private int currInstallIdx;
  private String currInstallPath;
  File file;
  PackageParser.Package info;
  private Iterator<String> itStr;
  private ApplicationInfo mAppInfo;
  private Context mContext;
  public boolean packageProcess = true;
  public String packageProcessName = null;
  private List<String> paths;
  public Map<String, String> pkgRenaming = new TreeMap(new Comparator()
  {
    public int compare(String paramString1, String paramString2)
    {
      if (paramString1 == null)
        return 0;
      return paramString1.compareTo(paramString2);
    }
  });
  public SecretUtil secretInstance = new SecretUtil();
  public String[] str = this.secretInstance.createKey(512);
  File tmpFile;
  boolean toPinYin = false;

  public InstallHelper(Context paramContext)
  {
    this.mContext = paramContext;
  }

  private boolean isAppRunning(Context paramContext)
  {
    Iterator localIterator;
    ActivityManager.RunningTaskInfo localRunningTaskInfo;
    List localList = ((ActivityManager)paramContext.getSystemService("activity")).getRunningTasks(100);
    if ((localList != null) && (localList.size() > 0))
      localIterator = localList.iterator();
    do
    {
      if (!(localIterator.hasNext()))
        return false;
      localRunningTaskInfo = (ActivityManager.RunningTaskInfo)localIterator.next();
    }
    while ((!(localRunningTaskInfo.topActivity.getPackageName().equals("com.lewa.app.filemanager"))) || (!(localRunningTaskInfo.baseActivity.getPackageName().equals("com.lewa.app.filemanager"))));
    return true;
  }

  public void clear()
  {
    this.paths = null;
    this.itStr = null;
  }

  public void cmdInstall(String paramString)
  {
    Logs.i("--- pkg 1 " + paramString);
    while (true)
    {
      String str1;
      try
      {
        this.info = getPackageInfo(Uri.fromFile(new File(paramString)));
        label439: label583: label369: str1 = PackageInstallManager.getInstance().getApkLabel(paramString);
      }
      catch (Exception localException2)
      {
        boolean bool2;
        try
        {
          int j = 0x1 & this.mContext.getPackageManager().getApplicationInfo(this.info.packageName, 1).flags;
          bool2 = false;
          if (j > 0)
          {
            ReportOfInstall.failed.add(new ReportInfo(paramString, str1));
            PackageInstallManager localPackageInstallManager4 = PackageInstallManager.getInstance();
            localPackageInstallManager4.faliureNum = (1 + localPackageInstallManager4.faliureNum);
            PackageInstallManager localPackageInstallManager5 = PackageInstallManager.getInstance();
            localPackageInstallManager5.unhandled = (-1 + localPackageInstallManager5.unhandled);
            bool2 = true;
          }
          if (!(bool2))
          {
            this.tmpFile = new File(Constants.getLewaHome());
            if (!(this.tmpFile.exists()))
              this.tmpFile.mkdirs();
            PackageInstallManager.getInstance().apkpath = paramString;
            this.file = new File(paramString);
            boolean bool3 = this.file.getAbsolutePath().equals(PinyinHelper.rawTransfer(this.file.getAbsolutePath()));
            i = 0;
            if (bool3)
            {
              this.toPinYin = i;
              if (i == 0)
                break label607;
              String str3 = this.secretInstance.encrypt(this.file.getAbsolutePath(), this.str[0], this.str[1]);
              this.packageProcess = false;
              this.packageProcessName = null;
              File localFile1 = this.file;
              File localFile2 = new File(this.file.getParent() + "/" + str3);
              this.tmpFile = localFile2;
              OperationUtil.copy(localFile1, localFile2);
              String str4 = this.tmpFile.getAbsolutePath();
              str5 = str4;
            }
          }
        }
        catch (Exception localException2)
        {
          String str2;
          try
          {
            Root.rootExec("pm install -r '" + str5 + "'");
            if (this.toPinYin)
            {
              this.tmpFile.delete();
              this.packageProcess = true;
              this.packageProcessName = this.info.packageName;
            }
            Logs.i("--- pkg 2 " + paramString);
            PackageInstallManager localPackageInstallManager3 = PackageInstallManager.getInstance();
            PackageParser.Package localPackage = this.info;
            str2 = null;
            if (localPackage != null)
              break label583;
            localPackageInstallManager3.packageInstalled(str2, -1, bool2, str1);
            return;
            localException2 = localException2;
            Logs.i("--- pkg eee  " + paramString);
            boolean bool1 = ReportOfInstall.failed.contains(paramString);
            bool2 = false;
            if (!(bool1));
            ReportOfInstall.failed.add(new ReportInfo(paramString, str1));
            PackageInstallManager localPackageInstallManager1 = PackageInstallManager.getInstance();
            localPackageInstallManager1.faliureNum = (1 + localPackageInstallManager1.faliureNum);
            PackageInstallManager localPackageInstallManager2 = PackageInstallManager.getInstance();
            localPackageInstallManager2.unhandled = (-1 + localPackageInstallManager2.unhandled);
            bool2 = true;
          }
          catch (Exception localException3)
          {
            localException3.printStackTrace();
            Logs.i("--- pkg eeeee  " + paramString);
            bool2 = true;
            break label369:
            str2 = this.info.packageName;
            break label439:
            localException1 = localException1;
            localException1.printStackTrace();
            return;
          }
        }
      }
      int i = 1;
      continue;
      label607: String str5 = paramString;
    }
  }

  public int getCurrInstallIdx()
  {
    return (1 + this.currInstallIdx);
  }

  public String getCurrInstallPath()
  {
    return this.currInstallPath;
  }

  public String getIteratorNext(List<String> paramList)
  {
    if (this.paths == null)
    {
      this.paths = paramList;
      this.itStr = paramList.iterator();
    }
    if (this.itStr.hasNext())
    {
      this.currInstallPath = ((String)this.itStr.next());
      this.currInstallIdx = paramList.indexOf(this.currInstallPath);
      Logs.e(" ---------- currInstallPath " + this.currInstallPath);
      return this.currInstallPath;
    }
    return null;
  }

  public PackageParser.Package getPackageInfo(Uri paramUri)
  {
    String str1 = paramUri.getPath();
    PackageParser localPackageParser = new PackageParser(str1);
    File localFile = new File(str1);
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    localDisplayMetrics.setToDefaults();
    return localPackageParser.parsePackage(localFile, str1, localDisplayMetrics, 0);
  }

  public List<String> getPaths()
  {
    String str1 = (String)SPUtil.getValue(this.mContext, "File", "apkpaths", String.class);
    if (this.paths == null)
      return Arrays.asList(str1.split(","));
    return this.paths;
  }

  public Integer getTotalInstallSum()
  {
    return Integer.valueOf(this.paths.size());
  }

  public boolean hasNext(String paramString)
  {
    if ((paramString == null) || (paramString.equals("end")))
      return false;
    Logs.i("-----------pathpath 111");
    return true;
  }

  public void install(String paramString1, String paramString2)
  {
    Intent localIntent = new Intent("android.intent.action.VIEW");
    localIntent.setDataAndType(Uri.fromFile(new File(paramString1)), "application/vnd.shortcut.package-archive");
    this.mContext.startActivity(localIntent);
  }

  public void tryInstall(String paramString)
  {
    cmdInstall(paramString);
  }

  public void uninstall(String paramString)
  {
    Intent localIntent = new Intent("android.intent.action.DELETE", Uri.parse("package:" + paramString));
    this.mContext.startActivity(localIntent);
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.explorer.func.setup.InstallHelper
 * JD-Core Version:    0.5.2
 */